package xmlS
{
	import main.XMLLoaderBase;
	
	public class NavigationXMLLoader extends XMLLoaderBase
	{
		private var _callBack:Function;
		private var _datas:Object = {};//用于存储所有已读信息
		private var _key:String;
		public function NavigationXMLLoader()
		{
			super();
		}
		
		public function init(keyStr:String,callBack:Function = null):void
		{
			_key = keyStr;
			_callBack = callBack;
			super.loadXml(keyStr,loadXMLComplete,null);
		}
		
		private function loadXMLComplete(value:XML):void
		{
			var xmlData:Object = {};
			xmlData.path = [];
			var xmlList:XMLList;
			var tempData:NavigationStruct;
			xmlList = value.child("viewspot");
			var spotList:Array = [];
			for(var i:int = 0;i < xmlList.length();i++)
			{
				tempData = new NavigationStruct();
				tempData.posX = xmlList[i].@x;
				tempData.posY = xmlList[i].@y;
				tempData.name = xmlList[i].@name;
				tempData.picUrl = xmlList[i].@picUrl;
				tempData.id = xmlList[i].@id;
				tempData.desc = xmlList[i].@desc;
				tempData.music = xmlList[i].@music;
				tempData.mp3Desc = String(xmlList[i]);
				tempData.scaleX = xmlList[i].@scaleX;
				tempData.scaleY = xmlList[i].@scaleY;
				tempData.gpsX = xmlList[i].@gpsX;
				tempData.gpsY = xmlList[i].@gpsY;
				tempData.offset = xmlList[i].@offset;
				tempData.star =  xmlList[i].@star;
				tempData.time =  xmlList[i].@time;
				if(tempData.id == "backGround")
				{
					xmlData.backGround = tempData;
				}
				else
				{
				spotList.push(tempData);
				}
			}
				xmlData.viewSpot = spotList;
				xmlList = value.child("path");
				for(i=0;i<xmlList.length();i++)
				{
					tempData = new NavigationStruct();
					tempData.posX = xmlList[i].@x;
					tempData.posY = xmlList[i].@y;
					tempData.name = xmlList[i].@name;
					tempData.picUrl = xmlList[i].@picUrl;
					tempData.id = xmlList[i].@id;
					tempData.desc = xmlList[i].@desc;
					tempData.music = xmlList[i].@mp3;
					tempData.mp3Desc = String(xmlList[i]);
					tempData.scaleX = xmlList[i].@scaleX;
					tempData.scaleY = xmlList[i].@scaleY;
					tempData.pathID = xmlList[i].@pathID;
					tempData.time = xmlList[i].@time;
					xmlData.path.push(tempData);
				}
				
				_datas[_key] = xmlData;
			if(_callBack != null)
			{
				_callBack(xmlData);
			}
		}
		
		public function  navigationData(value:String):Object
		{
			return _datas[value];
		}
		
	}
}


class NavigationStruct
{
	public var posX:Number;
	public var posY:Number;
	public var picUrl:String;
	public var name:String;
	public var desc:String;
	public var id:String;
	public var music:String;
	public var mp3Desc:String;
	public var scaleX:Number;
	public var scaleY:Number;
	public var gpsX:Number;
	public var gpsY:Number;
	public var offset:Number;
	public var pathID:String;
	public var star:int;
	public var time:uint;
}